package poly_.dynamic_;

import java.util.Date;

public class DynamicBinding {
    public static void main(String[] args) {
        // a的编译类型 A，运行类型 B
        A a = new B(); // 向上转型
        System.out.println(a.sum()); // 30
        System.out.println(a.sum1()); // 20
        Date date = new Date();
        System.out.println(date);
    }
}

//父类
class A {
    public int i = 10;

    //动态绑定机制
    //
    public int sum() {
        return getI() + 10;
    }

    public int sum1() {
        return i + 10;
    }

    public int getI() {
        return i;
    }
}

//子类
class B extends A {
    public int i = 20;
//    public int sum() {
//        return i + 20;
//    }

    public int getI() {
        return i;
    }

//    public int sum1() {
//        return i + 10;
//    }
}
